package com.server;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;
import com.database.*;
import java.util.*;
import java.sql.Timestamp;

public class FlightMapServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;
	private final String className = "Flight Map Servlet: ";

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		ConnectDB();
		String id = req.getParameter("id");
				
		try 
		{
			ArrayList departureTime = new ArrayList();
			ArrayList<String> departureLocation = new ArrayList<String>();
			ArrayList<String> arrivalLocation = new ArrayList<String>();
			ArrayList<String> flightID = new ArrayList<String>();
			
			Statement stmt = connection.createStatement();
			String sqlString = "select * from flight";
			ResultSet rs = stmt.executeQuery(sqlString);
			
			while (rs.next())
			{
				Timestamp ts = (Timestamp)rs.getObject("departureTime");
				departureTime.add(ts.getTime());
				
				departureLocation.add("'"+(String) rs.getObject("departureLocation")+"'");
				arrivalLocation.add("'"+(String) rs.getObject("arrivalLocation")+"'");
				flightID.add("'" + (String)rs.getObject("flightID")+"'");
			}

			req.setAttribute("departureTime", departureTime);
			req.setAttribute("departureLocation", departureLocation);
			req.setAttribute("arrivalLocation", arrivalLocation);
			req.setAttribute("flightID", flightID);
			
			req.setAttribute("id", id);
			req.getRequestDispatcher("admin/FlightMap.jsp").forward(req, resp);
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}

}

